package com.googlecode.astoolkit.utils {
	
	import flash.utils.Proxy;
	import flash.utils.flash_proxy;
	
	dynamic public class AbstractNode extends Proxy implements INode {
		
		private var _id:int;
		//private var _label:String;
		private var _path:String
		//private var _className:String;
		private var _children:Array;
		private var _parent:INode;
		//private var _instance:ISection;
		//private var _showInContextMenu:Boolean;
		
		private var _customProperties:Object = new Object();

		public function AbstractNode(data:XML) {
			_children = new Array();
			//instance = null;
			for each(var prop:XML in data.children()){
				if(prop.name() != "section"){
					//trace("prop-->" + prop.name() + ", value-->" + prop.valueOf());
					_customProperties[prop.name()] = prop.valueOf();
				}
			}
			//trace("-------------------------------------------------------");
		}

		public function addChildNode(node:INode):void {
			_children.push(node);
		}

		//
		flash_proxy override function callProperty(name:*, ... rest):* {
		//
		}

		// called when getting dynamic variables
		override flash_proxy function getProperty(name:*):* {
			if (name in _customProperties) {
				return _customProperties[name];
			}
			return "Error getProperty: Property '" + name + "' does not exist";
		}

		// called when setting dynamic variables
		override flash_proxy function setProperty(name:*, value:*):void {
			if(name!="_id" && name!="_path" && name!="_children" && name!="_parent"){
				//trace("setProperty: name-->" + name + ", value-->" + value);
				_customProperties[name] = value;
			}else{
				trace("Error setProperty: Property '" + name + "' is private");
			}
		}


		// Getter Setter de id
		public function set id(value:int):void {
			_id = value;
		}

		public function get id():int {
			return _id;
		}

		// Getter Setter de label
		/* public function set label (value:String):void{
			_label=value;
		}
		public function get label ():String{
			return _label;
		}	 */
		
		// Getter Setter de link
		 public function set path (value:String):void{
			_path = value;
		}
		public function get path ():String{
			return _path;
		} 

		// Getter Setter de children
		public function set children (value:Array):void{
			_children = value;
		}
		public function get children ():Array{
			return _children;
		}	
		
		// Getter Setter de className
		/* public function set className (value:String):void{
			_className=value;
		}
		public function get className ():String{
			return _className;
		} */
		// Getter Setter de instance
		/* public function set instance (value:ISection):void{
			_instance=value;
		}
		public function get instance ():ISection{
			return _instance;
		} */
		
		// Getter Setter de parent
		public function set parent (value:INode):void{
			_parent = value;
		}
		public function get parent ():INode{
			return _parent;
		}
		
		// Getter Setter de showInContextMenu
		/* public function set showInContextMenu (value:Boolean):void{
			_showInContextMenu=value;
		}
		public function get showInContextMenu ():Boolean{
			return _showInContextMenu;
		} */
	}
}